package com.xinchen.aiowaste.base

import android.os.Bundle
import android.text.TextUtils
import android.view.View
import android.widget.LinearLayout
import android.widget.TextClock
import android.widget.TextView
import com.blankj.utilcode.util.BarUtils
import com.blankj.utilcode.util.NetworkUtils
import com.blankj.utilcode.util.ToastUtils
import com.kongqw.network.monitor.enums.NetworkState
import com.maple.utils.ext.toVisible
import com.maple.utils.util.LogUtils
import com.xinchen.aiowaste.R
import com.maple.base.base.BaseActivity as Base

abstract class BaseActivity: Base() {

    override fun hasStatusBarMode(): Boolean = true
    override fun hasNetworkState(): Boolean = true

    override fun onBeforeCreate(savedInstanceState: Bundle?) {
        super.onBeforeCreate(savedInstanceState)
        BarUtils.setStatusBarVisibility(this,false)
        BarUtils.setNavBarVisibility(this,false)
    }
    override fun setStatusBarMode(color: Int, fitWindow: Boolean, light: Boolean) {
        super.setStatusBarMode(com.maple.res.R.color.trans, false, light)
    }

    override fun onNetWorkChange(networkState: NetworkState) {
        super.onNetWorkChange(networkState)
        LogUtils.logGGQ("当前网络：${networkState.name}")
//        showToast(networkState.name)
        showNetworkState(networkState)
    }
    open fun setTitle(title: String?) {
        if(!TextUtils.isEmpty(title)) {
            findViewById<TextView>(R.id.tv_title_center)?.text = title
        }
    }


    open fun showClockTime() {
        findViewById<TextClock>(R.id.tc_time)?.toVisible()
    }

    open fun showNetworkState(networkState: NetworkState) {
        findViewById<TextView>(R.id.tv_network_state)?.let {
            it.text = "网络状态：${networkState.name}"
            it.toVisible()
        }
    }

    open fun onBackClick() {
        findViewById<LinearLayout>(R.id.ll_title_left)?.let {
            it.toVisible()
            it.setOnClickListener {
                onFinish()
            }
        }
    }
}